package cn.edu.javaweb.userServlet;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.edu.javaweb.utils.DBUtil;


@WebServlet("/PersonalRecruitSelectServlet")
public class PersonalRecruitSelectServlet extends HttpServlet {
	DBUtil db;
	private static final long serialVersionUID = 1L;
    
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//设置编码方式
	    request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");   //不设置会乱码
				
		//从Login.html获取id
		HttpSession session = request.getSession(true);     // 如果不存在 session 会话，则创建一个 session 对象
		String userid = session.getAttribute("id").toString();
		
		db = new DBUtil();
		List<Map<String, String>> list = db.getList("select * from enroll e left join notice n on n.id=e.recruit_id where userid="+userid+"");
		request.setAttribute("enrolls", list);
		System.out.println(list);
		
		response.setContentType("text/html;charset=utf-8");
		RequestDispatcher rd=request.getRequestDispatcher("volunteer/user/PersonalRecruit.jsp");
	    rd.forward(request, response);		
	}

}
